import myAxios from "../index";

export default {
  // 登录接口
  login: (data: SysUser) =>
    myAxios({
      url: "/login",
      method: "post",
      data: {
        userName: data.userName,
        password: data.password,
      },
    }),

  // 查询所有用户
  findAll: () =>
    myAxios({
      url: "/admin/system/sysUser/findAll",
      method: "get",
    }),

  // 根据ID查询用户
  findById: (id: number) =>
    myAxios({
      url: `/admin/system/sysUser/findById/${id}`,
      method: "get",
    }),

  // 添加用户
  addUser: (data: SysUser) =>
    myAxios({
      url: "/admin/system/sysUser/add",
      method: "post",
      data,
    }),

  // 更新用户
  updateUser: (data: SysUser) =>
    myAxios({
      url: "/admin/system/sysUser/update",
      method: "put",
      data,
    }),

  // 删除用户
  deleteUser: (id: number) =>
    myAxios({
      url: `/admin/system/sysUser/delete/${id}`,
      method: "delete",
    }),

  // 分页查询用户
  page: (data: SysUser) =>
    myAxios({
      url: "/admin/system/sysUser/page",
      method: "post",
      data,
    }),

  // 为用户分配角色
  assignRoles: (userId: number, roleIds: number[]) =>
    myAxios({
      url: `/admin/system/sysUser/assignRoles/${userId}`,
      method: "post",
      data: roleIds,
    }),

  // 获取用户角色
  getUserRoles: (userId: number) =>
    myAxios({
      url: `/admin/system/sysUser/getUserRoles/${userId}`,
      method: "get",
    }),

  // 获取用户菜单
  getUserMenus: () =>
    myAxios({
      url: "/admin/system/sysUser/getUserMenus",
      method: "get",
    }),
};
